__author__ = 'maksimfominov'

import psycopg2
import properties

connection_string="host=localhost"+" "\
                  +"port="+properties.options['db_port']+" "\
                  +"dbname="+properties.options['db_name']+" "\
                  +"user="+properties.options['db_user']+" "\
                  +"password="+properties.options['db_password']

def db_connect():
    conn = psycopg2.connect(connection_string)
    cur = conn.cursor()
#cur.execute("DROP TABLE IF EXISTS TEST;")
#cur.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")
#cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def"))
#cur.execute("SELECT * FROM test;")
#conn.commit()
#print(cur.fetchone())
#def db_disconnect():

def execute_cursor():
    db_connect.cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def"))
    db_connect.conn.commit()

def db_disconnect():
    db_connect.cur.close()
    db_connect.conn.close()

def select():
    return db_connect.cur.execute("SELECT * FROM test;")

execute_cursor
print select
db_disconnect